<?php
/**
 * Created by PhpStorm.
 * User: QK
 * Date: 2018-07-25
 * Time: 下午 3:18
 */
namespace app\backstage\controller;
use app\backstage\model\GoodspecModel;
use app\backstage\validate\GoodspecValidate;
use cmf\controller\AdminBaseController;

class GoodspecController extends AdminBaseController{
    /**
     * 商品规格列表
     */
    public function index(){
//        $param = $this->request->param();
        //获取规格
        $g       = new GoodspecModel();
        $rest    = $g->goodspeclist();
//        $rest->appends($param);
        $this->assign('users',$rest);
        $this->assign('page',$rest->render());
        return $this->fetch('goodslist');
    }
    /**
     * 添加商品规格页面
     */
    public function add(){
        return $this->fetch('goodsadd');

    }
    /**
     * 添加规格操作
     */
    public function addPost(){
        $date       = $this->request->param();
        $validate   = new GoodspecValidate();
        if (!$validate->check($date)) {
            $this->error($validate->getError());
        }
        $g          = new GoodspecModel();
        $rest       = $g->goodspecadd($date);
        if($rest != false){
            $this->success('操作成功！');
        }else{
            $this->error('操作失败！');
        }

    }
    /**
     * 修改规格页面
     */
    public function detail(){
        //获取指定规格
        $id        = $this->request->param('id');
        $g         = new GoodspecModel();
        $rest      = $g->getGone($id);
        $this->assign('rest',$rest);
        return $this->fetch();
    }
    /**
     * 修改规格操作
     */
    public function detailPost(){
        $date     = $this->request->param();
        $g        = new GoodspecModel();
        $rst      = $g->goodspecupdate($date);
        if($rst != false){
            $this->success('修改成功！','Goodspec/index');
        }else{
            $this->error('修改失败');
        }
    }
    /**
     * 删除规格
     */
    public function del(){
        $date     = $this->request->param();
        $id       =$date['id'];
        $g        = new GoodspecModel();
        $rst      = $g->goodspecdelete($id);
        if($rst != false){
            $this->success('删除成功！','Goodspec/index');
        }else{
            $this->error('删除失败','Goodspec/index');
        }
    }
}